/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jwu2.log;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Rolf
 */
public class Logger {
    
    private static Logger singleton;
    private List<LoggerI> loggers;
    
    private Logger() {
        loggers = new ArrayList<LoggerI>();
    }
    
    private void realLog(String msg) {
        for(LoggerI l : loggers) {
            l.log(msg);
        }
    }
    
    public static void log(String msg) {
        singleton().realLog(msg);
    }
    
    public static void logln(String msg) {
        singleton().realLog(msg+"\n");
    }

    public static Logger singleton() {
        if( singleton == null ) {
            singleton = new Logger();
        }
        
        return singleton;
    }
    
    public static void registerLogger(LoggerI log) {
        singleton().realRegister(log);
    }

    private void realRegister(LoggerI log) {
        loggers.add(log);
    }
}
